﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;

namespace HZ.DrugTrade.Web.Admin.RelationQuery
{
    public partial class DeleteRelationToCompany_PS : System.Web.UI.Page
    {
        IBLL.IBLL_Company iBLL_Company = Factory.BLL_Company();

        IBLL_Log iBLL_Log = BLL.BLL_Log.Instance;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GVDataBind();
            }
        }

        protected void GVDataBind()
        {
            #region 编辑查询条件
            string where = "where 1=1";

            //配送企业ID
            if (txtCompanyId.Text.Trim() != "")
            {
                where += " and a.Companyid_ps='" + txtCompanyId.Text + "'";
            }

            if (txtCompanyName.Text.Trim() != "")
            {
                where += " and b.CompanyName like '" + txtCompanyName.Text + "%'";
            }

            #endregion

            int totalRecord = 0;
            GvRelaion.DataSource = iBLL_Company.GetCompanySCAndCompanyPsAndHospital(where, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalRecord);
            AspNetPager1.RecordCount = totalRecord;
            GvRelaion.DataBind();
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            GVDataBind();
        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            GVDataBind();
        }

        //将删除与该配送企业有关的所有配送关系：生产企业与配送企业；医院与配送企业
        protected void lkbtnDelRelation_Click(object sender, EventArgs e)
        {
            LinkButton lkbtn = sender as LinkButton;
            GridViewRow row = lkbtn.NamingContainer as GridViewRow;
            string companyid_ps = row.Cells[1].Text.ToString();
            int message = iBLL_Company.DeleteRelationSCAndPSAndHospital(companyid_ps);
            if (message > 0)
            {
                iBLL_Log.WriteLog(CurrentAccount.GetUser().UserName, "删除配送关系", CurrentAccount.GetUser().UserID);
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "alert('删除成功！')", true);
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "alert('删除失败！')", true);
            }
            GVDataBind();
        }
    }
}
